
package com.it.flowable.listener.leave;

import com.it.flowable.common.constants.BpmLeaveConstant;
import com.it.flowable.entity.leave.ActLeaveProcessExtVO;
import com.it.flowable.mapper.leave.ActLeaveProcessExtVOMapper;
import com.it.flowable.service.leave.bpm.BpmLeaveDao;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * 一个完整流程的 开始和结束处理
 */
@Service("bpmLeaveBSListener")
@Slf4j
public class BpmLeaveBSListener implements Serializable {

    @Resource
    private BpmLeaveDao bpmLeaveDao;

    public void executeProcess(DelegateExecution execution) throws Exception {
        try {
            if ("start".equals(execution.getEventName())) {
                // 流程启动记录流程扩展信息 放在 BpmLeaveStartProcessServiceReImpl.startProcess 处理，用于展示流程图
//                bpmLeaveDao.insertActLeaveProcessExtVO(execution);
            }
            if ("end".equals(execution.getEventName())) {
                // 流程结束记录流程完成状态
                bpmLeaveDao.updateActLeaveProcessExtVO(execution.getId(), BpmLeaveConstant.LEAVE_STATUS_COMPLETE);
            }
        } catch (Exception e) {
            log.error("创建、修改流程扩展信息出错BpmLeaveBSListener:");
            e.printStackTrace();
            throw new Exception("创建、修改流程扩展信息出错BpmLeaveBSListener:", e);
        }
    }


}
